<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 配置对象</title>

</head>

<body>
    <!-- 
        重要的属性
        method 
        url       必填的
        params
        headers
        data

        baseURL   设置基础 url
        timeout   超时时间的设置
        cancelToken  用来取消 AJAX 请求
     -->
    <button>点击获取英雄</button>
    <button>点击获取段子</button>


    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <script>
        let btns = document.querySelectorAll("button");
        // api.xiaohigh.com   127.0.0.1:8090  http://127.0.0.1

        //axios 的默认配置   作用: 简化, 维护方便
        axios.defaults.method = 'GET'; //默认的请求类型为 get
        axios.defaults.timeout = 1000; //默认的超时时间为 1000
        axios.defaults.baseURL = 'http://api.xiaohigh.com:8090'; //设置 url 的基础结构

        btns[0].onclick =async function () {
            let result = await axios({
                url: '/lol'
            })
            console.log(result);
        }

        btns[1].onclick = async function(){
            let result = await axios.get('/duanzi');
            console.log(result);
        }


    </script>


</body>

</html>